package com.sesame.common.utils;



/**
 * @author keying.xia
 * @date 2017/12/13
 */
public class ResponseUtils {

    public static ResponseBean success(Object o){
        ResponseBean responseBean = new ResponseBean();

        if (o instanceof ResultStatusCode){
            ResultStatusCode resultStatusCode = (ResultStatusCode)o;
            responseBean.setMsg(resultStatusCode.getMsg());
            responseBean.setCode(resultStatusCode.getCode());
        }else {
            responseBean.setData(o);
            responseBean.setCode(ResultStatusCode.OK.getCode());
            responseBean.setMsg(ResultStatusCode.OK.getMsg());
        }

        return responseBean;
    }


    public static ResponseBean success(){
        return success(null);
    }

    public static ResponseBean error(ResultStatusCode resultStatusCode){
        ResponseBean responseBean = new ResponseBean();
        responseBean.setMsg(resultStatusCode.getMsg());
        responseBean.setCode(resultStatusCode.getCode());
        return responseBean;
    }

    public static ResponseBean error(ResultStatusCode resultStatusCode,Object o){
        ResponseBean responseBean = new ResponseBean();
        responseBean.setMsg(resultStatusCode.getMsg());
        responseBean.setCode(resultStatusCode.getCode());
        responseBean.setData(o);
        return responseBean;
    }

    public static ResponseBean error(Integer code , String errMsg){
        ResponseBean responseBean = new ResponseBean();
        responseBean.setMsg(errMsg);
        responseBean.setCode(code);
        return responseBean;
    }


}
